package com.example.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.R;
import com.example.entity.Doctor;
import com.example.entity.Hospital;
import com.example.service.IHospitalService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 医院 前端控制器
 * </p>
 *
 * @author wyx
 * @since 2025-03-12
 */
@RestController
@RequestMapping("/hospital")
@Slf4j
@CrossOrigin//跨域访问
@Api(tags = "医院管理模块")
public class HospitalController {
    @Autowired
    IHospitalService hospitalService;

    //查询医院列表
    @RequestMapping("/query")
    public R hospitallist() {
        log.info("查询医院列表");
        return R.success( hospitalService.list());
    }

    //分页查询医院列表
    @RequestMapping("/page")
    public R hospitalpage(Integer page, Integer pageSize, String name) {
        log.info("分页查询医院列表page:{},pageSize:{}", page, pageSize);
        Page<Hospital> pageInfo = new Page<>(page, pageSize);

        LambdaQueryWrapper<Hospital> queryWrapper = new LambdaQueryWrapper<>();
        if (name != null){
            queryWrapper.like(Hospital::getName, name);
        }

        return R.success(hospitalService.page(pageInfo, queryWrapper));
    }

}
